// 登陆
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { homeVoiceActorRecomItemType, HomeVoiceActorRecomResType, VoiceActorDetailResType } from './type'
import { homeRecommendVoiceActorApi, voiceActorDetailApi, homeRecommendVoicePackageApi, voicePackageDetailApi, voicePackageCommentApi } from "@renderer/api/voice"

export const useVoiceStore = defineStore('voice', () => {
    //首页推荐列表
    const recommendVoiceActorList = ref<homeVoiceActorRecomItemType[]>([])
    //声优详情
    const voiceActorInfo = ref<homeVoiceActorRecomItemType>()

    //语音包列表数据
    const recomVoicePackageList = ref([])

    //语音包详情
    const voicePackageDetail = ref(null)

    //语音包评论数据
    const voicePackageComments = ref([])

    //首页推荐声优
    const homeRecommendVoiceActor = async () => {
        const res: HomeVoiceActorRecomResType = await homeRecommendVoiceActorApi()
        if (res.code == 0) {
            recommendVoiceActorList.value = res.data
            return res
        }
    }
    //推荐声优详情
    const getVoiceActorDetail = async (id: number) => {
        const res: VoiceActorDetailResType = await voiceActorDetailApi(id)
        if (res.code == 0) {
            voiceActorInfo.value = res.data
            return res
        }
    }

    //首页分页语音包
    const getVoicePackageList = async (page) => {
        const res = await homeRecommendVoicePackageApi(page)
        if (res.code == 0) {
            // recomVoicePackageList.value = res.result.data
            return res.result
        }
    }

    //语音包详情
    const getVoicePackageDetail = async (id: number) => {
        const res = await voicePackageDetailApi(id)
        if (res.code == 0) {
            voicePackageDetail.value = res.data
            return res
        }
    }

    //语音包评论
    const getVoicePackageComments = async (id: number,page: number) => {
        const res = await voicePackageCommentApi(id,page)
        if (res.code == 0) {
            return res.result
        }
    }
    return {
        recommendVoiceActorList,
        voiceActorInfo,

        homeRecommendVoiceActor,
        getVoiceActorDetail,
        recomVoicePackageList,
        getVoicePackageList,
        voicePackageDetail,
        getVoicePackageDetail,
        voicePackageComments,
        getVoicePackageComments
    }
}
)